home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Your Apple Games Gallery 2
/
Your Apple Games Gallery II (Side B)(MindCraft Publishing Corporation)(1989).do
/
LIFE.bas
< prev
next >
Wrap
BASIC Source File
|
2021-12-11
|
10KB
|
264 lines
1 REM ************************
2 REM * LIFE *
3 REM * BY RAUL CARTAYA *
4 REM * COPYRIGHT (C) 1982 *
5 REM * MINDCRAFT PUBL. CORP.*
6 REM * CONCORD, MA 01742 *
9 REM ************************
15 TEXT : HOME : VTAB 7: LOMEM: 4 *4096
16 P$ = "WELCOME TO LIFE"
17 GOSUB 20: GOTO 22
18 XDRAW 1 AT FN PC(X), FN PC(Y): RETURN
20 PRINT TAB( 20 - LEN(P$)/2);P$: RETURN
21 PRINT TAB( 20 - LEN(P$)/2);P$;: RETURN
22 VTAB 10:P$ = "DO YOU NEED AN INTRODUCTION?": GOSUB 20
24 P$ = "(Y OR N, RETURN) ": GOSUB 21
26 INPUT "";A$
28 IF A$ = "Y" THEN GOSUB 5000
30 GOSUB 6000
32 DEF FN NX(X) = 35 *(X <0) +X *(X <35)
34 DEF FN NY(Y) = 20 *(Y <0) +Y *(Y <20)
36 DEF FN PC(Z) = 8 *Z +4
50 DIM P%(34,19),N%(34,19),D%(34,19)
55 DIM CL%(734),DL%(734)
60 DD$ = CHR$(4):XX$ = "LIFE PATTERN "
150 REM PREPARE FOR PLAYER STATE
160 GOSUB 250
180 HGR :NM = 0
190 GOSUB 4630
195 X = 17:Y = 10
200 GOTO 1000
250 REM EXPLAIN PLAYER MENU
260 HOME
270 PRINT "PRESS ANY KEY TO GO INTO PLAYER STATE."
280 PRINT "IN THAT STATE, THE FOLLOWING COMMANDS"
290 PRINT "ARE AVAILABLE:"
300 POKE 33,32: POKE 32,8: PRINT
310 PRINT "X - PLACE/REMOVE MARKER"
330 PRINT "G - TURN ON GRID"
340 PRINT "N - TURN OFF GRID"
350 PRINT "U - MOVE CURSOR UP"
360 PRINT "D - MOVE DOWN"
370 PRINT "L - MOVE LEFT"
380 PRINT "R - MOVE RIGHT"
390 PRINT "Y - UP AND LEFT"
400 PRINT "I - UP AND RIGHT"
410 PRINT "S - DOWN AND LEFT"
420 PRINT "F - DOWN AND RIGHT"
430 PRINT "C - COPY TO DISK"
440 PRINT "A - ADD FROM DISK"
450 PRINT "W - WIPE AND RE-START"
460 PRINT "ESC - GO TO RUN STATE"
470 PRINT "H - RE-DISPLAY THIS PAGE"
475 PRINT "Q - QUIT PROGRAM (END)"
478 TEXT
480 POKE 32,0
490 PRINT "HIT ANY KEY TO CONTINUE";: GET Z$: HOME : RETURN
1000 REM PLAYER STATE
1010 POKE -16304,0: HOME : VTAB 21
1020 PRINT "COMMANDS - X G N U D L R Y I S F C A Q"
1030 PRINT " H FOR HELP ESC TO RUN"
1040 PRINT "MARKERS: X,Y:";
1050 VTAB 23: HTAB 10: PRINT NM" ";
1060 HTAB 31: PRINT X","Y" ";
1065 GOSUB 18
1070 GET A$
1080 GOSUB 18
1090 IF A$ = "X" THEN 1300
1100 IF A$ = "G" THEN 1370
1110 IF A$ = "N" THEN 1350
1120 IF A$ = "U" THEN 1410
1130 IF A$ = "D" THEN 1420
1140 IF A$ = "L" THEN 1430
1150 IF A$ = "R" THEN 1440
1160 IF A$ = "Y" THEN 1450
1170 IF A$ = "I" THEN 1460
1180 IF A$ = "S" THEN 1470
1190 IF A$ = "F" THEN 1480
1200 IF A$ = "C" THEN 1500
1210 IF A$ = "A" THEN 1700
1220 IF A$ = "W" THEN CLEAR : TEXT : GOTO 32
1230 IF A$ = CHR$(27) THEN 3500
1240 IF A$ = "H" THEN TEXT : GOSUB 250: GOTO 1000
1250 IF A$ = "Q" THEN PRINT : TEXT : HOME : END
1260 GOTO 1050
1300 REM PLACE/REMOVE MARKER
1320 GOSUB 4000: GOTO 1050
1350 REM GRID OFF (ON AT 2ND LINE)
1360 HCOLOR= 0
1370 FOR Y2 = 8 TO 152 STEP 8: FOR X2 = 8 TO 272 STEP 8: HPLOT X2,Y2: NEXT : NEXT
1380 HCOLOR= 3: GOTO 1050
1400 REM CURSOR MOVES
1410 DY = -1: GOTO 1443
1420 DY = 1: GOTO 1443
1430 DX = -1: GOTO 1443
1440 DX = 1
1443 X = FN NX(X +DX)
1445 Y = FN NY(Y +DY)
1448 DX = 0:DY = 0: GOTO 1050
1450 DX = -1: GOTO 1410
1460 DX = 1: GOTO 1410
1470 DX = -1: GOTO 1420
1480 DX = 1: GOTO 1420
1500 REM COPY TO DISK
1510 IF NOT NM THEN 1050
1520 P$ = "COPY TO DISK": GOSUB 1800
1530 PRINT DD$"WRITE"F$
1540 PRINT NM
1550 FOR X = 0 TO 34: FOR Y = 0 TO 19
1560 IF NOT P%(X,Y) THEN 1600
1570 X2 = X:Y2 = Y
1580 IF XO THEN X2 = X2 -X4:Y2 = Y2 -Y4
1590 GOSUB 18: PRINT X2: PRINT Y2: GOSUB 18
1600 NEXT : NEXT
1610 GOTO 1780
1700 REM ADD FROM DISK
1710 P$ = "ADD FROM DISK": GOSUB 1800
1720 PRINT DD$"READ"F$
1730 INPUT M
1740 FOR I = 1 TO M
1750 INPUT X,Y: IF XO THEN X = X +X4:Y = Y +Y4
1755 IF X >34 THEN X = X -34
1757 IF Y >19 THEN Y = Y -19
1760 X = FN NX(X):Y = FN NY(Y): GOSUB 18: GOSUB 4000: GOSUB 18
1770 NEXT
1780 HOME : VTAB 21:P$ = F$ +" DONE"
1790 PRINT DD$"CLOSE"F$:X = X4:Y = Y4: GOSUB 20: GOSUB 18: GOTO 1000
1800 HOME : VTAB 21: GOSUB 18: GOSUB 20:X4 = X:Y4 = Y
1810 PRINT "NAME FOR "XX$;: INPUT F$:F$ = XX$ +F$
1820 PRINT DD$"OPEN"F$
1830 INPUT "MEASURE FROM CURSOR? (Y OR N)";Z$
1840 XO = 0: IF Z$ = "Y" THEN XO = 1
1850 RETURN
2999 REM RUN STATE
3000 NC = 0:ND = 0:NG = NG +1: HOME
3010 X = 0
3020 FOR I = 1 TO CN
3030 Y = CL%(I): IF Y <0 THEN X = X +1: GOTO 3120
3040 GOSUB 18
3050 D = DL%(I)
3070 N = N%(X,Y) +D:N%(X,Y) = N
3080 IF P%(X,Y) THEN ON N GOTO 3100,3100,3110,3110,3100,3100,3100,3100,3100
3090 IF N < >3 THEN 3110
3100 GOSUB 4000
3110 GOSUB 18
3120 NEXT
3490 REM GENERATION STATS
3500 HOME
3505 IF PEEK( -16384) = 155 THEN I = PEEK( -16368): GOTO 195
3510 VTAB 21: PRINT "GENERATION "NG; TAB( 21)"MARKERS: "NM
3520 PRINT "NET CHANGE: "ND; TAB( 21)"BIRTHS+DEATHS: "NC
3530 IF NOT NM THEN PRINT "ALL LIFE HAS BECOME EXTINCT...": GOTO 3505
3540 IF NOT NC THEN PRINT "LIFE IS STABLE...": GOTO 3505
3550 PRINT "HIT ESC FOR PLAYER STATE";
3560 GOSUB 4500: GOTO 3000
3990 REM BIRTH/DEATH
4000 XDRAW 2 AT FN PC(X), FN PC(Y)
4010 P%(X,Y) = 1 -P%(X,Y)
4020 D = -1: IF P%(X,Y) THEN D = 1
4025 IF X = 0 OR X = 34 OR Y = 0 OR Y = 19 THEN 4120
4030 D%(X -1,Y -1) = D%(X -1,Y -1) +D
4035 D%(X -1,Y) = D%(X -1,Y) +D
4040 D%(X -1,Y +1) = D%(X -1,Y +1) +D
4045 D%(X,Y -1) = D%(X,Y -1) +D
4047 D%(X,Y) = D%(X,Y) +D
4050 D%(X,Y +1) = D%(X,Y +1) +D
4060 D%(X +1,Y -1) = D%(X +1,Y -1) +D
4070 D%(X +1,Y) = D%(X +1,Y) +D
4080 D%(X +1,Y +1) = D%(X +1,Y +1) +D
4090 NM = NM +D
4100 NC = NC +1
4105 ND = ND +D
4106 IF X <XL THEN XL = X
4107 IF Y <YL THEN YL = Y
4108 IF X >XH THEN XH = X
4109 IF Y >YH THEN YH = Y
4110 RETURN
4115 REM BIRTH/DEATH AT EDGE
4120 FOR X2 = X -1 TO X +1
4130 FOR Y2 = Y -1 TO Y +1
4140 X3 = FN NX(X2):Y3 = FN NY(Y2)
4150 D%(X3,Y3) = D%(X3,Y3) +D
4160 NEXT : NEXT
4190 GOTO 4090
4490 REM LIST OF "CHANGES?"
4500 CN = 0
4510 XL = FN NX(XL -1):XH = FN NX(XH +1): IF XL > = XH THEN I = XL:XL = XH:XH = I: IF XL = 0 OR XH = 34 THEN XL = 0:XH = 34
4520 YL = FN NY(YL -1):YH = FN NY(YH +1): IF YL > = YH THEN I = YL:YL = YH:YH = I: IF YL = 0 OR YH = 19 THEN YL = 0:YH = 19
4530 IF XL = 0 THEN 4550
4540 FOR I = 0 TO XL -1:CN = CN +1:CL%(CN) = -1: NEXT
4550 FOR X = XL TO XH: FOR Y = YL TO YH
4560 IF NOT D%(X,Y) THEN NEXT : GOTO 4610
4570 D = D%(X,Y)
4580 CN = CN +1:D%(X,Y) = 0
4590 CL%(CN) = Y:DL%(CN) = D
4600 NEXT
4610 CN = CN +1:CL%(CN) = -1
4620 NEXT
4630 XL = 34:XH = 0:YL = 19:YH = 0
4640 RETURN
5000 REM INSTRUCTIONS
5010 HOME
5020 PRINT "LIFE IS A GAME OF PATTERNS. A PATTERN"
5030 PRINT "IS MADE UP OF INHABITED PLACES (OCCUPIED";
5040 PRINT "BY MARKERS) AND EMPTY PLACES. ANY ONE"
5050 PRINT "PATTERN IS CALLED A GENERATION.": PRINT
5060 PRINT "YOU PLAY LIFE BY ENTERING THE PATTERN"
5070 PRINT "FOR THE FIRST GENERATION, AND THEN WAT-"
5080 PRINT "CHING IT EVOLVE. EACH GENERATION DETER-"
5090 PRINT "MINES THE PATTERN FOR THE NEXT GENERA-"
5100 PRINT "TION BASED ON THE LAWS OF BIRTH,"
5110 PRINT "SURVIVAL, AND DEATH. YOU SIMPLY WATCH"
5120 PRINT "THE PATTERNS CHANGE AS THE GENERATIONS"
5130 PRINT "EVOLVE.": PRINT
5140 PRINT "IN ADDITION, YOU MAY CHANGE THE PATTERN"
5150 PRINT "AT THE END OF ANY GENERATION. PRESSING"
5160 PRINT "'ESC' WILL SWITCH FROM THE RUN STATE"
5170 PRINT "BACK TO PLAYER STATE, WHERE YOU MAY MO-"
5180 PRINT "DIFY THE PATTERN, SAVE IT TO DISK, RE-"
5190 PRINT "TURN TO THE RUN STATE, OR END THE PRO-"
5200 PRINT "GRAM.": GOSUB 5470
5210 PRINT "FOLLOWING ARE THE THREE BASIC LAWS."
5220 PRINT "REMEMBER THAT EACH PLACE ON THE BOARD"
5230 PRINT "HAS EIGHT ADJACENT PLACES. 'HAVING TWO"
5240 PRINT "NEIGHBORS' MEANS HAVING TWO ADJACENT"
5250 PRINT "PLACES WHICH ARE INHABITED.": PRINT
5260 PRINT "BIRTH - AN EMPTY PLACE WILL GIVE BIRTH"
5270 HTAB 9: PRINT "TO A MARKER IN THE NEXT GENERA-"
5280 HTAB 9: PRINT "TION IF IT HAS EXACTLY 3 NEIGH-"
5290 HTAB 9: PRINT "BORS.": PRINT
5300 PRINT "SURVIVAL - AN INHABITED PLACE WILL STILL";
5310 HTAB 9: PRINT "BE INHABITED IN THE NEXT GENERA-";
5320 HTAB 9: PRINT "TION IF IT HAS 2 OR 3 NEIGHBORS.";: PRINT
5330 PRINT "DEATH - AN INHABITED PLACE WILL BECOME"
5340 HTAB 9: PRINT "EMPTY IN THE NEXT GENERATION"
5350 HTAB 9: PRINT "(THE MARKER WILL DIE) IF IT HAS"
5360 HTAB 9: PRINT "LESS THAN 2 NEIGHBORS OR MORE"
5370 HTAB 9: PRINT "THAN 3 (DEATH FROM LONELINESS OR";
5380 HTAB 9: PRINT "OVERCROWDING).": GOSUB 5470
5390 PRINT "LIFE IS PLAYED ON A 35X20 BOARD. HORI-"
5400 PRINT "ZONTAL LOCATIONS (X) ARE (LEFT TO RIGHT)";
5410 PRINT "0 THROUGH 34. VERTICAL LOCATIONS (Y) ARE";
5420 PRINT "(TOP TO BOTTOM) 0 THROUGH 19.": PRINT
5430 PRINT "THE BOARD WRAPS AROUND BOTH VERTICALLY"
5440 PRINT "AND HORIZONTALLY, SO THE TOP AND BOT-"
5450 PRINT "TOM ROWS (OR THE LEFTMOST AND RIGHTMOST"
5460 PRINT "COLUMNS) ARE ADJACENT. HAVE FUN!"
5470 VTAB 23: GOTO 490
6000 REM PUT IN SHAPE TABLE
6010 POKE 768,2: POKE 769,0: POKE 770,6: POKE 771,0:
6020 POKE 772,35: POKE 773,0: POKE 774,8: POKE 775,8:
6030 POKE 776,8: POKE 777,54: POKE 778,54: POKE 779,54:
6040 POKE 780,39: POKE 781,36: POKE 782,36: POKE 783,60:
6050 POKE 784,54: POKE 785,54: POKE 786,54: POKE 787,39:
6060 POKE 788,36: POKE 789,36: POKE 790,60: POKE 791,54:
6070 POKE 792,54: POKE 793,54: POKE 794,39: POKE 795,36:
6080 POKE 796,36: POKE 797,60: POKE 798,54: POKE 799,54:
6090 POKE 800,54: POKE 801,95: POKE 802,0: POKE 803,8:
6100 POKE 804,8: POKE 805,200: POKE 806,59: POKE 807,247:
6110 POKE 808,30: POKE 809,54: POKE 810,14: POKE 811,14:
6120 POKE 812,45: POKE 813,12: POKE 814,12: POKE 815,36:
6130 POKE 816,28: POKE 817,92: POKE 818,0:
6140 POKE 232,0: POKE 233,3: REM SHAPE TABLE POINTER.
6150 HCOLOR= 3: SCALE= 1: ROT= 0
6160 RETURN